<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title th:replace="common/base::pagetitle"></title>
    <link th:replace="common/base::static"/>
    <link rel="stylesheet" th:href="@{/static/plugins/easyui/themes/material/easyui.css}">
    <link rel="stylesheet" th:href="@{/static/plugins/easyui/themes/icon.css}">
    <link rel="stylesheet" th:href="@{/static/css/wlb-treegrid.css}">
</head>
<body style="background-color: #f2f2f2;">

<div id="kPage" class="layui-fluid" style="padding: 0">
    <div class="layui-row">
        <!-- 主要内容块 -->
        <div class="layui-col-md12" id="kMainContentCol">
            <div class="layui-fluid wlb-fluid-padding15">
                <div class="layui-card">
                    <form>
                        <div class="layui-form layui-card-header wlb-card-header-auto">
                            <div class="layui-form-item">
<!--                                <div class="layui-inline">-->
<!--                                    <label class="layui-form-label">名称</label>-->
<!--                                    <div class="layui-input-inline">-->
<!--                                        <input type="text" name="name" placeholder="请输入" autocomplete="off" class="layui-input">-->
<!--                                    </div>-->
<!--                                </div>-->
                                <div class="layui-inline">
<!--                                    <button class="layui-btn " lay-submit="" lay-filter="kTableSearchFilter">-->
<!--                                        <i class="layui-icon layui-icon-search"></i>-->
<!--                                    </button>-->
                                    <button class="layui-btn " type="reset">
                                        <i class="layui-icon layui-icon-refresh-1"></i>
                                    </button>
                                </div>
                            </div>
                        </div>

                    </form>


                        <input type="hidden" id="compId" name="compId" th:value="${compId}">
                    <div class="layui-card-body">
                        <table id="kRelationTable" lay-filter="kRelationTable"></table>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

<script th:replace="common/base::context"></script>
<script th:replace="common/base::mainjs"></script>
<script th:src="@{/static/plugins/easyui/easyloader.js}"></script>

<script type="text/html" id="statusTpl">
    {{# if(d.status === 0) { }}
    <span class="layui-badge layui-bg-green">正常</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-gray">禁用</span>
    {{# } }}
</script>

<script type="text/html" id="typeTpl">
    {{#  if(d.compType === '0'){ }}
    <span class="layui-badge layui-bg-blue">供应商</span>
    {{#  } else if(d.compType === '1') { }}
    <span class="layui-badge layui-bg-orange">核心企业</span>
    {{#  } else if(d.compType === '2') { }}
    <span class="layui-badge layui-bg-green">银行</span>
    {{#  } else { }}
    <span class="layui-badge layui-bg-cyan">其他</span>
    {{# } }}
</script>

<script type="text/html" id="sourceTpl">
    {{#  if(d.source == 0){ }}
    <span class="layui-badge layui-bg-blue">集采推送</span>
    {{#  } else if(d.source == 1) { }}
    <span class="layui-badge layui-bg-orange">其他</span>
    {{# } }}
</script>



<!-- 头部工具栏模板 -->
<script type="text/html" id="headToolbarTpl">
    <button class="layui-btn layui-btn-sm" lay-event="edit">修改</button>
</script>


<!--表格行工具栏模板-->
<script type="text/html" id="rowToolbarTpl">
    <!--&lt;!&ndash;	 {{# if(d.type == 1) { }}&ndash;&gt;-->
    <!--	 <a class="layui-btn layui-btn-xs" data-event="add" onclick="active.add(this)" data-comId="{{d.comId}}"><i class="layui-icon layui-icon-add-1"></i></a>-->
    <!--&lt;!&ndash;	 {{# } }}&ndash;&gt;-->
<!--    <a class="layui-btn layui-btn-normal layui-btn-xs" data-event="edit" onclick="active.edit(this)" data-id="{{d.id}}"><i class="layui-icon layui-icon-edit"></i>编辑</a>-->
<!--    <a class="layui-btn layui-btn-danger layui-btn-xs" data-event="del" onclick="active.del(this)" data-id="{{d.id}}" data-orgId="{{d.orgId}}"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
</script>

<script type="text/javascript" th:inline="none">
    var active;
    layui.use(['element', 'form', 'layer', 'table', 'laytpl'], function () {
        var elemet = layui.element, form = layui.form, layer = layui.layer, table = layui.table;
        var tableId = 'kRelationTable';

        var compId = document.getElementById("compId").value;
        // 实例化table
        var tableIns = table.render({
            elem: '#' + tableId
            ,url: api.sys.deptBankList + "?compId="+compId//数据接口
            ,response:{dataName: 'items'}
            , page: {    //开启分页
                curr: 1,
                limit: 10
             }
            , toolbar: '#headToolbarTpl'
            , cols: [[ //表头
                // {type: 'checkbox', fixed: 'left'}
                , {field: 'compName', title: '机构名称', width: 120, fixed: false}
                , {field: 'compType', title: '类型', width: 100, align: 'center', templet: '#typeTpl', fixed: false}
                , {field: 'describe', title: '描述',  width: 220, fixed: false}
                , {field: 'pushStatus', title: '推送状态',  width: 220, fixed: false}
                // , {field: 'source', title: '机构来源',  width: 220, templet: '#sourceTpl', fixed: false}
                // , {field: '', title: '操作', width: 235, fixed: 'right', templet: '#rowToolbarTpl'}
            ]]
        });
        var area = ['450px', '530px'];

        // 监听表格头部事件
        table.on('toolbar(' + tableId + ')', function (obj) {
                        var checkStatus = table.checkStatus(obj.config.id);
            var checkData = checkStatus.data; // 得到选中的数据

        });


        $(window).resize(function () {
            treeGridKit.fitRightFrozenCol(tableId);
        });

        // 列格式化函数
        var formatter = {
            rowToolbar: function (value, row, index) {
                return wlbKit.renderTpl('rowToolbarTpl', row);
            },
            status: function (value, row, index) {
                return wlbKit.renderTpl('statusTpl', row);
            },
            type: function (value, row, index) {
                return wlbKit.renderTpl('typeTpl', row);
            },
            source: function (value, row, index) {
                return wlbKit.renderTpl('sourceTpl', row);
            }
        };



        // 监听查询
        form.on('submit(kTableSearchFilter)', function (obj) {
            var params = obj.field;
            log('seach=', params); //

            tableIns.reload({
                where: params,
                page: {curr: 1}
            });
            return false;

        });

        // 绑定监听回车事件
        wlbKit.bindEnterEventForLayuiForm();

    });
</script>

</body>
</html>
